/**
 * 
 */
package com.wbcs.jbsf.auth.interceptor;

import java.io.IOException;
import java.io.StringWriter;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;

import com.wbcs.config.component.application.report.ReportBean;
import com.wbcs.jbsf.util.JacksonMapper;
import com.wbcs.system.ReportRequest;
import com.wbcs.system.intercept.AbsInterceptorDefaultAdapter;
import com.wbcs.util.Consts;

/**
 * 用于追加管理权限的情况
 * @author hawkfly
 */
public class ItprApdAdminAuth extends AbsInterceptorDefaultAdapter
{
    @Override
	public Object afterLoadData(ReportRequest rrequest,ReportBean rbean,Object typeObj,Object dataObj)
    {
        ObjectMapper jsonMapper = JacksonMapper.getInstance();
        StringWriter sw = new StringWriter();
        JsonGenerator gen;
        try
        {
            gen=new JsonFactory().createJsonGenerator(sw);
            jsonMapper.writeValue(gen, dataObj); 
            gen.close();
        }catch(IOException e)
        {
            e.printStackTrace();
        }
        String datasStr = sw.toString().replace("pid","pId");
        StringBuffer paramsBuf=new StringBuffer();
        paramsBuf.append("{pageid:'"+rrequest.getPagebean().getId()+"'"); 
        paramsBuf.append(",reportid:'"+rbean.getId()+"'");
        paramsBuf.append(",datas:"+datasStr+"}");
        rrequest.getWResponse().addOnloadMethod("onloadTree",paramsBuf.toString(),false);
        
        rrequest.getWResponse().setStatecode(Consts.STATECODE_NONREFRESHPAGE);
        
      //判断当前登录用户是否含有管理员角色，如果含有则追加管理权限到菜单中，否则不追加
        return dataObj;
    }
}